<?php
/**
 * 质押及质押算力
 */
namespace app\common\model;

use think\Model;

class MiningPledge extends Model
{
    protected $name = 'mining_pledge';

    /**
     * 列表
     * @param $order
     * @param int $limit
     * @param int $page
     */
    public static function getList($limit = 20,$page = 1,$where=[],$order = 'id desc'){
        $data = self::where($where)->order($order)->paginate(['list_rows'=>$limit,'page'=>$page])->toArray();
        return $data;
    }

    /**
     * 查询所有
     * @param array $where 查询条件
     * @param string $order 排序
     * @return MiningPledge[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getAll($where = [],$order = 'id desc'){
        return self::where($where)->order($order)->select();
    }

    /**
     * 统计表
     * @param $mid 用户ID
     * @param $where
     * @param int $mining_oneself   1:总质押 2:总算力
     */
    public static function sum_arithmetical($mid,$where = [],$mining_oneself = 1){
        $where['mining_oneself'] = ['=',$mining_oneself];
        return self::where('mid',$mid)->where($where)->sum('num');
    }

}